import path from 'path'
import webpack from 'webpack'
import memoryfs from 'memory-fs'

export default (fixture, options = {}) => {
  const compiler = webpack({
    mode:'development',
    context: __dirname,
    entry: `./${fixture}`,
    output: {
      path: path.resolve(__dirname),
      filename: 'bundle.js',
    },
    module: {
      rules: [
        {
          test: /\.leis$/,
          use: {
            loader: path.resolve(__dirname, '../src/leis-loader.js'),
            options: {
              name: 'leisuchu'
            }
          }
        },
        {
          test: /(\.scss|\.sass)$/,
          use: [
            'style-loader',
            'css-loader',
            'sass-loader'
          ]
        }]
    }
  });

  compiler.outputFileSystem = new memoryfs();

  return new Promise((resolve, reject) => {
    compiler.run((err, stats) => {
      if (err || stats.hasErrors()) reject(stats);

      resolve(stats);
    });
  });
};